﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace GraphEditor
{
	internal class AlgorithmManager
	{
		static private AlgorithmManager instance = null;

		static public AlgorithmManager Instance
		{
			get
			{
				if (instance == null)
					instance = new AlgorithmManager();

				return instance;
			}
		}

		List<Algorithm> algorithms = new List<Algorithm>();

		public Algorithm [] Algorithms
		{
			get { return algorithms.ToArray(); }
		}

		private AlgorithmManager()
		{
			LoadAlgorithms();
		}

		private void LoadAlgorithms()
		{
			string path = Application.ExecutablePath;
			path = Path.GetDirectoryName(path);
			//path += Path.DirectorySeparatorChar + "Algorithms";

			string [] files = Directory.GetFiles(path);

			foreach (string file in files)
			{
				if (Path.GetExtension(file) != ".dll")
					continue;

				Algorithm alg;

				try
				{
					alg = new Algorithm(file);
					algorithms.Add(alg);
				}
				catch
				{
					continue;
				}
			}
		}
	}
}
